package advance_2;

import java.util.Objects;

public class Dog {
    private String name;
    public Dog(String n){
        name=n;
    }
    public void bite(Dog d){
        //this咬了d
        System.out.println(this.name+"咬了"+d.name+",咬下来一嘴毛");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dog dog = (Dog) o;
        return Objects.equals(name, dog.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
/*    @Override
    public int hashCode() {
        return name==null?0:name.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof Dog)){
            return false;
        }
        Dog d=(Dog)obj;
        return this.name.equals(d.name);
    }*/

    @Override
    public String toString() {
        return "小狗"+name;
    }
}
